package com.atgm.mall.gmmailproduct.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

/**
 * 分布式唯一id生成器
 */

@Service
public class IdGeneratorService {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    private static final String KEY_PREFIX = "id:game:";

    public Long incrementId(String keySuffix) {
        //原子性
        return stringRedisTemplate.opsForValue().increment(KEY_PREFIX + keySuffix);
    }

}
